package app;

import java.util.*;

import utils.FilePack;

import com.StarMicronics.StarIOSDK.*;
import com.StarMicronics.StarIOSDK.PrinterFunctions.*;
import com.starmicronics.stario.*;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.view.*;
import android.view.View.OnClickListener;
import android.widget.*;

public class RejectView {
	private EditText name;
	private EditText reason;
	private long ticketID;
	public AcceptTerms accceptView;

	
	private void cancel() {
		AppDelegate.sharedInstance().layout.removeView(view);
	}
	
	private void save() {
		if (name.getText().length() > 0 && reason.getText().length() > 0) {
			Dictionary<String, Object> c = AppDelegate.sharedInstance().getMain().ticketsDataSource.memoryObject.get(Long.valueOf(ticketID));
			if (c != null) {
				c.put(TicketList.REJECT_NAME, name.getText().toString());
				c.put(TicketList.REJECT_REASON, reason.getText().toString());
			}
			cancel();
			accceptView.back();
			accceptView = null;
		} else {
			WaittingAlertView alert = WaittingAlertView.createWaittingAlertView();
			alert.setTitle(FilePack.getStringByID(STRING_ID.STR_REJECT_ALERT));
			alert.show();
		}
	}
	
	public RejectView(long param) {
		loadXml();
		ticketID = param;
		Dictionary<String, Object> c = AppDelegate.sharedInstance().getMain().ticketsDataSource.memoryObject.get(Long.valueOf(ticketID));
		if (c != null) {
			name.setText((String)c.get(TicketList.REJECT_NAME));
			reason.setText((String)c.get(TicketList.REJECT_REASON));
		}
		AppDelegate.sharedInstance().layout.addView(view);
	}
	
	private View view;
	private void loadXml() {
		TextView text;
		Button button;
        view = (View)AppDelegate.sharedInstance().activity.getLayoutInflater().inflate(R.layout.reject, null);
        
        name = (EditText) view.findViewById(R.id.name);
        name.setHint(FilePack.getStringByID(STRING_ID.STR_NAME));
        
        text = (TextView) view.findViewById(R.id.title_reason);
        text.setText(FilePack.getStringByID(STRING_ID.STR_REASON));
        
        reason = (EditText) view.findViewById(R.id.reason);
        
        button = (Button) view.findViewById(R.id.button_back);
        button.setText(FilePack.getStringByID(STRING_ID.STR_BACK));
        button.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				cancel();
			}
		});
        
        button = (Button) view.findViewById(R.id.button_save);
        button.setText(FilePack.getStringByID(STRING_ID.STR_SAVE));
        button.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				save();
			}
		});
        
        view.setOnClickListener(new OnClickListener() {
			public void onClick(View arg0) {
				cancel();
			}
		});
	}
}
